package alarm;

public abstract class AbstractFilter implements Filter {

	Observer observer;

	public AbstractFilter() {
		observer = null;
	}

	public abstract boolean accept(Event e); // abstract due to request

	@Override
	public void notifyEvent(Event e) {
		if (observer == null)
			throw new RuntimeException("No observer defined!");
		if ( accept(e) ) 
			observer.notifyEvent(e);
		// else observer.notifyEvent(new Event("filter rejected")); // TODO to remove
	}

	@Override
	public void setObserver(Observer obs) {
		if (observer == null)
			observer = obs;
		else
			throw new RuntimeException("An Attempt to register twice!");

	}

}
